// Book类
case class Book(title: String, author: String, ISBN: String)

// Library类
class Library {
  var availableBooks: List[Book] = List()
  var borrowedBooks: List[Book] = List()

  // 添加新书
  def addBook(book: Book): Unit = {
    availableBooks = book :: availableBooks
    println(s"Book '${book.title}' added to the library.")
  }

  // 借出书籍
  def borrowBook(book: Book): Unit = {
    if (availableBooks.contains(book)) {
      availableBooks = availableBooks.filterNot(_ == book)
      borrowedBooks = book :: borrowedBooks
      println(s"Book '${book.title}' borrowed successfully.")
    } else {
      println(s"Book '${book.title}' is not available for borrowing.")
    }
  }

  // 归还书籍
  def returnBook(book: Book): Unit = {
    if (borrowedBooks.contains(book)) {
      borrowedBooks = borrowedBooks.filterNot(_ == book)
      availableBooks = book :: availableBooks
      println(s"Book '${book.title}' returned successfully.")
    } else {
      println(s"Book '${book.title}' was not borrowed from this library.")
    }
  }

  // 打印可用书籍和已借出书籍列表
  def printBooks(): Unit = {
    println("Available Books:")
    availableBooks.foreach(book => println(s"${book.title} by ${book.author}"))
    println("\nBorrowed Books:")
    borrowedBooks.foreach(book => println(s"${book.title} by ${book.author}"))
  }
}
/*
// 测试
object Main extends App {
  // 创建几本书和图书馆对象
  val book1 = Book("Scala Programming", "Martin Odersky", "978-0981531649")
  val book2 = Book("Clean Code", "Robert C. Martin", "978-0132350884")
  val book3 = Book("Design Patterns", "Erich Gamma", "978-0201633610")

  val library = new Library()

  // 添加书籍到图书馆
  library.addBook(book1)
  library.addBook(book2)
  library.addBook(book3)

  // 借出一本书
  library.borrowBook(book1)

  // 归还一本书
  library.returnBook(book1)

  // 打印图书馆的书籍列表
  library.printBooks()
}
*/
